//首页内容js
$(window).bind("load", function () {

    var pre_sidebar_width = 0;
    var pre_main_container = 0;
    var page_cententWitdhC = $.page_cententWitdhC = function () {
        var sidebar_width = $("#sidebar").width();
        var main_container = $(".main-container").width();
        if ($("#sidebar").is(':hidden')) {
            sidebar_width = 0;
        }

        if (pre_sidebar_width != sidebar_width || pre_main_container != main_container) {
            pre_sidebar_width = sidebar_width;
            pre_main_container = main_container;
            var cz = 5;
            if (pre_sidebar_width > 0 && pre_sidebar_width < 60) {
                cz = 10;
            }
            var width = pre_main_container - pre_sidebar_width - cz;
            $(".ddp_index_tab").width(width);
        }
        $('.ddp_index_tab').tabTriggerScroll();
    }

    $(window).resize(function () {
        page_cententWitdhC();
        $('.ddp_index_tab').displayCur();
    });

    //F5刷新后显示最后也页面内容
    var hash = window.location.hash;
    if (hash && hash.indexOf("/welcome.html") == -1) {
        $(".sidebar-menu li a[href='" + hash.substr(1) + "']:eq(0)").click();
    }
    //页签内的工具条定位
    var $page_scroll_buttons = $('.page-scroll-buttons');
    var page_scroll_scrollH1 = $page_scroll_buttons.offset().top;
    var page_scroll_scrollH3 = $(window).height();
    $page_scroll_buttons.css({"position": 'absolute', 'top': 87, 'right': 0});
    $(window).scroll(function () {
        var page_scroll_scrollH2 = $(document).scrollTop();
        if (page_scroll_scrollH2 > page_scroll_scrollH1 || page_scroll_scrollH2 == page_scroll_scrollH1) {
            $page_scroll_buttons.css({"position": 'fixed', 'top': 45, 'right': 0}).fadeTo(100, 1);
        } else {
            $page_scroll_buttons.css({"position": 'absolute', 'top': 87}).fadeTo(100, 1);
        }
        if (page_scroll_scrollH2 > page_scroll_scrollH3 || page_scroll_scrollH2 == page_scroll_scrollH3) {
            $('.page-scroll-buttons .hand-up').fadeIn(200);
        } else {
            $('.page-scroll-buttons .hand-up').fadeOut(200);
        }
    });
    $('.page-scroll-buttons .hand-up').click(function () {
        $('body,html').animate({"scrollTop": 0}, 500);
    });
    $("#refresh-toggler").click(function () {
        var hash_ = $(".ddp_index_tab .nav-tabs li.active a").attr("href");
        if (hash_) {
            $(".sidebar-menu li a[tabid='" + hash_.substr(1) + "']:eq(0)").click();
        }
    });
    $(document).keydown(function (e) {//当用户按F5是刷新当前显示页面的页签
        //用户已经登录的情况下执行以下判断
        if ($.loginUser) {
            if (e.keyCode === 116) {
                $.stopPropagation(e);
                $("#refresh-toggler").click();
            } else if (e.ctrlKey) {
                if (e.keyCode === 82) {
                    $.stopPropagation(e);
                    $("#refresh-toggler").click();
                }
            }
        }
    });
    ////////////////////////////////////////////////////////////////////////////////////
});